package controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@javax.servlet.annotation.WebServlet(urlPatterns = "/user")
public class User extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json; charset=utf-8");
		PrintWriter pWriter = response.getWriter();

		JSONObject jsonObject = new JSONObject();
		jsonObject.put("data", JSONArray.fromObject(new entities.User("jim", "男", 21)));
		String jsonstr = jsonObject.toString();

		pWriter.write(jsonstr);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}

}
